package cz.uhk.max.log;

public class ProgressLogger {
	
	public static ProgressLogger progressLogger;
	private Logger logger;
	private Progress progress;

	
	public synchronized static ProgressLogger getProgressLogger() {
		if (progressLogger == null) {
			progressLogger = new ProgressLogger();
		}
		return progressLogger;
	}
	
	public synchronized Logger getLogger() {
		return logger;
	}
	
	public void init(Progress progress) {
		this.progress = progress;
		logger = new FileLogger(this.progress.getName());
	}
	
	public Progress getProgress() {
		return progress;
	}
	
	public synchronized void log(String text) {
		if (logger != null) {
			logger.log(text);
		}
	}
	
	public synchronized String read() {
		if (logger != null) {
			return logger.read();
		} else {
			return "";
		}
	}
	
	public synchronized void clear() {
		if (logger != null) {
			logger.clear();
		}
	}
	
	public boolean isFinished() {
		if (logger != null) {
			return logger.isFinished();
		} else {
			return true;
		}
	}
	
	public String getName() {
		if (logger != null) {
			return logger.getName();
		} else {
			return null;
		}
	}

}
